#ifndef STATISTICS_
#define STATISTICS_
#include "ParseTree.h"
#include <map>
#include "string.h"
#include<algorithm>
#include<vector>
#include<iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>

using namespace std;

struct relation 
{    
	long  numTuples;                    
	int numPartition;     
	map <string, long> Attr;     
	relation()
	{	
		numTuples=0;
		numPartition=-1;
	}	
};

struct  numTuples {
	bool deleted;
	double **value;
	int partition;
};

class Statistics
{
	private:
		int PartitionNum;
		map<string,relation> RelationMap;
		map <string, vector <string> > attrMap;
		map <int, vector<string> > PartitionMap;
		vector<string>  relationSet;
		vector<string> cnfAtts;

		//getters for copyme function
		map<string, relation> * GetRelationMap()     
		{          
			return &RelationMap;   
		} 
		map<int, vector<string> > *GetPartitionMap()     
		{          
			return &PartitionMap; 
		} 

		int GetPartitionNumber()
		{
			return PartitionNum;
		}
		map<string, vector <string> > * GetAttrMap()
		{
			return &attrMap;
		} 
	public:
		Statistics();
		Statistics(Statistics &copyMe);	 // Performs deep copy
		~Statistics();

		void AddRel(char *relName, int numTuples);
		void AddAtt(char *relName, char *attName, int numDistincts);
		void CopyRel(char *oldName, char *newName);

		void Read(char *fromWhere);
		void Write(char *fromWhere);

		void  Apply(struct AndList *parseTree, char *relNames[], int numToJoin);
		double Estimate(struct AndList *parseTree, char **relNames, int numToJoin);
		bool CheckErrors(struct AndList *ParseTree, char *relNames[], int numToJoin);
};

#endif
